package com.gpframework.module.purchase.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.purchase.domain.GpPurchaseIncomingInspect;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.math.BigDecimal;

import java.util.Date;

/**
 * @ClassName GpPurchaseIncomingInspectReq
 * @Author gpframework
 * @Date 2024-01-09
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpPurchaseIncomingInspectReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("缺货报库存申请表id")
     private Long productionApplicationId;
     @ApiModelProperty("做货明细表id")
     private Long purchasingDetailsId;
     @ApiModelProperty("排单表id")
     private Long procureSchedulingId;
     @ApiModelProperty("到货单id")
     private Long purchaseReceiptId;
     @ApiModelProperty("订单号")
     private String sn;
     @ApiModelProperty("来料时间")
     private Date incomingTime;
     @ApiModelProperty("胚布基础表id")
     private Long supplierGreyClothId;
     @ApiModelProperty("供应商名称")
     private String supplierName;
     @ApiModelProperty("产品基础表id")
     private Long produceProductId;
     @ApiModelProperty("产品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String colour;
     @ApiModelProperty("数量（条数）")
     private Integer quantity;
     @ApiModelProperty("批号")
     private String batchNo;
     @ApiModelProperty("总码数（空）/公斤数")
     private Integer totalQuantity;
     @ApiModelProperty("打码规格基础表id")
     private String codingSpecificationsId;
     @ApiModelProperty("打码规格")
     private String codingSpecifications;
     @ApiModelProperty("标签规格")
     private String tagSpecifications;
     @ApiModelProperty("抽查数量（条）")
     private Integer samplingQuantity;
     @ApiModelProperty("纸管")
     private String paperTube;
     @ApiModelProperty("对色情况")
     private String colorContrastSituation;
     @ApiModelProperty("检验状态 0未检验， 1已检验")
     private String status;
     @ApiModelProperty("跟单人id")
     private Long followUpId;
     @ApiModelProperty("跟单人名称")
     private String followUpName;
     @ApiModelProperty("跟单时间")
     private Date followUpTime;
     @ApiModelProperty("操作人id")
     private Long operatorId;
     @ApiModelProperty("操作人名称")
     private String operatorName;
     @ApiModelProperty("操作时间")
     private Date operatorTime;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpPurchaseIncomingInspect> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias + "create_time");
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (this.getProductionApplicationId() != null){
        lqw.eq(alias+"production_application_id" ,this.getProductionApplicationId());
        }
        if (this.getPurchasingDetailsId() != null){
        lqw.eq(alias+"purchasing_details_id" ,this.getPurchasingDetailsId());
        }
        if (this.getProcureSchedulingId() != null){
        lqw.eq(alias+"procure_scheduling_id" ,this.getProcureSchedulingId());
        }
        if (this.getPurchaseReceiptId() != null){
        lqw.eq(alias+"purchase_receipt_id" ,this.getPurchaseReceiptId());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.eq(alias+"sn" ,this.getSn());
        }
        if (this.getIncomingTime() != null){
        lqw.eq(alias+"incoming_time" ,this.getIncomingTime());
        }
        if (this.getSupplierGreyClothId() != null){
        lqw.eq(alias+"supplier_grey_cloth_id" ,this.getSupplierGreyClothId());
        }
        if (StringUtils.isNotBlank(this.getSupplierName())){
            lqw.like(alias+"supplier_name",this.getSupplierName());
        }
        if (this.getProduceProductId() != null){
        lqw.eq(alias+"produce_product_id" ,this.getProduceProductId());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getColour())){
            lqw.like(alias+"colour",this.getColour());
        }
        if (this.getQuantity() != null){
        lqw.eq(alias+"quantity" ,this.getQuantity());
        }
        if (StringUtils.isNotBlank(this.getBatchNo())){
        lqw.eq(alias+"batch_no" ,this.getBatchNo());
        }
        if (this.getTotalQuantity() != null){
        lqw.eq(alias+"total_quantity" ,this.getTotalQuantity());
        }
        if (StringUtils.isNotBlank(this.getCodingSpecificationsId())){
        lqw.eq(alias+"coding_specifications_id" ,this.getCodingSpecificationsId());
        }
        if (StringUtils.isNotBlank(this.getCodingSpecifications())){
        lqw.eq(alias+"coding_specifications" ,this.getCodingSpecifications());
        }
        if (StringUtils.isNotBlank(this.getTagSpecifications())){
        lqw.eq(alias+"tag_specifications" ,this.getTagSpecifications());
        }
        if (this.getSamplingQuantity() != null){
        lqw.eq(alias+"sampling_quantity" ,this.getSamplingQuantity());
        }
        if (StringUtils.isNotBlank(this.getPaperTube())){
        lqw.eq(alias+"paper_tube" ,this.getPaperTube());
        }
        if (StringUtils.isNotBlank(this.getColorContrastSituation())){
        lqw.eq(alias+"color_contrast_situation" ,this.getColorContrastSituation());
        }
        if (StringUtils.isNotBlank(this.getStatus())){
        lqw.eq(alias+"status" ,this.getStatus());
        }
        if (this.getFollowUpId() != null){
        lqw.eq(alias+"follow_up_id" ,this.getFollowUpId());
        }
        if (StringUtils.isNotBlank(this.getFollowUpName())){
            lqw.like(alias+"follow_up_name",this.getFollowUpName());
        }
        if (this.getFollowUpTime() != null){
        lqw.eq(alias+"follow_up_time" ,this.getFollowUpTime());
        }
        if (this.getOperatorId() != null){
        lqw.eq(alias+"operator_id" ,this.getOperatorId());
        }
        if (StringUtils.isNotBlank(this.getOperatorName())){
            lqw.like(alias+"operator_name",this.getOperatorName());
        }
        if (this.getOperatorTime() != null){
        lqw.eq(alias+"operator_time" ,this.getOperatorTime());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.colour", this.getSearchName()));
        }

        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
